﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HPCERP.Model;

namespace HPCERP.BusinessObject
{
    public class BankAccountBO
    {

        hpc_erpEntities ctx = new hpc_erpEntities();

        public BankAccount[] GetList(int id_Company)
        {
            var BankAccounts = from c in ctx.BankAccount.Include("Bank") where c.Bank.Company.ID_Company == id_Company orderby c.ID_BankAccount select c;
            return BankAccounts.ToArray();
        }

        public void Insert(BankAccount BankAccount)
        {
            ctx.BankAccount.AddObject(BankAccount);
            ctx.SaveChanges();
        }

        public void Update(BankAccount BankAccount)
        {
            ctx.BankAccount.ApplyChanges(BankAccount);
            ctx.SaveChanges();
        }

        public void Delete(int id)
        {
            var bankAccount = (from c in ctx.BankAccount where c.ID_BankAccount == id select c).First();
            ctx.BankAccount.DeleteObject(bankAccount);
            ctx.SaveChanges();
        }
    }
}
